package com.inno.subject.controller.controller;

import com.inno.subject.common.entity.CommonReturnType;
import com.inno.subject.controller.convert.SubjectRankDTOConverter;
import com.inno.subject.controller.dto.SubjectRankDTO;
import com.inno.subject.domain.entity.SubjectRankBO;
import com.inno.subject.domain.service.SubjectRankDomainService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author sean
 * 答题排行榜
 */
@RestController
@RequestMapping("/subject/rank")
public class SubjectRankController {

    @Resource
    private SubjectRankDomainService subjectRankDomainService;

    /**
     * 获取排行榜数据
     */
    @PostMapping("/getRankInfo")
    public CommonReturnType<List<SubjectRankDTO>> getRankInfo(@RequestBody(required = false) SubjectRankDTO subjectRankDTO){

        SubjectRankBO subjectRankBO = SubjectRankDTOConverter.INSTANCE.convertDTOToBO(subjectRankDTO);

        List<SubjectRankBO> boList = subjectRankDomainService.getRankInfo(subjectRankBO);
        return CommonReturnType.success(SubjectRankDTOConverter.INSTANCE.convertBOListToDTOList(boList));
    }
}
